﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Prism.Events;
using Prism.Services.Dialogs;
using SoonCode.FocusTest.Events;
using SoonCode.FocusTest.Models;
using SoonCode.FocusTest.Views;

namespace SoonCode.FocusTest.Utils
{
    public class DialogUtil
    {
        public static void Show(IEventAggregator aggregator,string msg)
        {
            EventInfo info = new EventInfo();
            info.Type = "test";
            info.Data["title"] = "系统提示";
            info.Data["msg"] = msg;
            aggregator.GetEvent<ShowMessageEvent>().Publish(info);
        }


        public static string Prompt(IDialogService service, string msg,Func<string,bool> checkAction=null,string defaultValue="")
        {
            DialogParameters parameters = new DialogParameters();
            parameters.Add("DialogTitle", "系统提示");
            parameters.Add("Message", msg);
            parameters.Add("CheckAction", checkAction);
            parameters.Add("DefaultValue",defaultValue);
            string result = "";
            service.ShowDialog(nameof(InputBox),parameters, res =>
            {
                if (res.Result == ButtonResult.Yes)
                    result = res.Parameters.GetValue<string>("result");
            }, "myDialogWindow");
            return result;
        }
    }
}
